package com.wt.struggle.goodbye.sq.adapter

import android.content.Context
import android.support.v7.widget.RecyclerView
import android.util.Log
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.LinearLayout
import com.wt.struggle.goodbye.R
import com.wt.struggle.goodbye.base.Config
import com.wt.struggle.goodbye.base.ProBaseAdapter
import com.wt.struggle.goodbye.info.NewsInfo
import com.wt.struggle.goodbye.info.VideoInfo
import com.xin.lv.yang.utils.utils.ImageUtil

/**
 * 显示图片
 */
class ContentImageAdapter(
    context: Context,
    list: ArrayList<VideoInfo>,
    val len: Int,
    val joupCode: Int
) :

    ProBaseAdapter<VideoInfo>(context, list) {

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {

        val vvInfo = list[position]
        var w = 0
        var h = 0

        val imagePath = Config.GET_IMAGE_URL + vvInfo.id

        Log.i("result", "len---------$len")

        when (len) {

            1 -> {
                w = getW(context) - context.resources.getDimension(R.dimen.dp_20).toInt()

                Log.i("result", "------" + vvInfo.width + "------" + vvInfo.height)

                h = context.resources.getDimension(R.dimen.dp_200).toInt()
            }

            2 -> {
                w = (getW(context) - context.resources.getDimension(R.dimen.dp_20).toInt()) / 2

                h = if (vvInfo.width != null && vvInfo.height != null && vvInfo.width != 0 && vvInfo.height != 0) {
                    w * vvInfo.height / vvInfo.width

                } else {
                    context.resources.getDimension(R.dimen.dp_180).toInt()
                }
            }

            else -> {
                w = (getW(context) - context.resources.getDimension(R.dimen.dp_20).toInt()) / 3
                h = w
            }
        }

        val vh = holder as VH

        vh.imageView.layoutParams = FrameLayout.LayoutParams(w, h)

        ImageUtil.getInstance().loadRoundCircleImage(context, vh.imageView, imagePath, 0, 4)

    }

    override fun onCreateView(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
        return VH(inflater.inflate(R.layout.image_view_layout, parent, false))
    }

    override fun onUpdateHolder(holder: RecyclerView.ViewHolder, position: Int, payloads: MutableList<Any>) {

    }

    inner class VH(view: View) : RecyclerView.ViewHolder(view) {

        val imageView = view.findViewById<ImageView>(R.id.imageViewPic)

    }
}